package com.rtuwrapper.messaging;

import com.rtuwrapper.processing.Integer16;
import com.rtuwrapper.processing.Register;

import static com.rtuwrapper.ModbusConstants.READ_INTEGER;
import static com.rtuwrapper.ModbusConstants.READ_REGISTER;

public class ReadIntegerRequest extends BaseRequest<Integer16, Integer> {

    public ReadIntegerRequest() {
        super(READ_INTEGER);
    }

    public ReadIntegerRequest(int address) {
        super(READ_INTEGER, new Integer16(address, 0));
    }

    @Override
    public void setData(int address, Integer value) {
        setModbusDataObject(new Integer16(address, value));
    }

    @Override
    public void setValue(Integer value) {
        setModbusDataObject(new Integer16(-1, value));
    }

    @Override
    public byte[] getEncodedMessage(int slaveId) {
        return getMessageProcessor().buildReadMessage(slaveId, READ_REGISTER, getModbusData().getAddress(), 1);
    }

}
